package com.cdtu.store.item.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtu.store.common.utils.PageUtils;
import com.cdtu.store.common.utils.Query;
import org.apache.commons.lang.StringUtils;

import com.cdtu.store.item.dao.SkuDao;
import com.cdtu.store.common.entity.SkuEntity;
import com.cdtu.store.item.service.SkuService;


@Service("skuService")
public class SkuServiceImpl extends ServiceImpl<SkuDao, SkuEntity> implements SkuService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<SkuEntity> wrapper = new QueryWrapper<SkuEntity>();
        String spuid = (String) params.get("spuid");
        if (!StringUtils.isEmpty(spuid)){
            wrapper.eq("spu_id",spuid);
        }
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.and((w) -> {
                w.eq("id",key).or().like("title",key);
            });
        }
        String enable = (String) params.get("enable");
        if (!StringUtils.isEmpty(enable)){
            wrapper.eq("enable",enable);
        }
        IPage<SkuEntity> page = this.page(
                new Query<SkuEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }


}